<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/18
 * Time: 15:05
 */

namespace Home\Controller;
use Think\Controller;

class MembersController extends Controller {
    /**
     * 会员列表页
     */
    public function index()
    {
        //判断用户有没有登陆
        if(!is_login()) {
            $this->redirect('User/login');
        }
        $sites = D('Members');
        $userid =session('uid');
        $data = $sites->getDataById();
        $order = D('Order');
        if($list = $order->selectById($userid))
        {
            $this->assign('list',$list);
        }else{
            $this->assign('list',1);
        }

        if(empty($data))
        {
            $info = array();
            $info['message'] = '暂时没有数据，请填充数据';
            $this->assign('data',$info);
        }
        $this->assign('data',$data);
        $this->display('center');

    }

    /**
     * 密码修改页
     */
    public function update()
    {
        //判断用户有没有登陆
        if(!is_login()) {
            $this->redirect('User/login');
        }
        $this->display('index');
    }

    /**
     * 广告购买处理
     */
    public function shopCart()
    {
        //判断用户的有没有登陆
        if(!is_login()) {
            $this->redirect('User/login');
        }
        $data = array();
        $data['position'] = I('post.ads',0,'intval');
        $num = I('post.nums',0,'intval');
        $data['price'] = I('post.prices',0,'htmlspecialchars').'00';
        $status = substr($num,0,1);
        $data['nums'] = substr(strrev($num),0,-1);
        $data['status'] = 0;//订单状态
        $data['user_id']= session('uid');
        $order = D('Order');
        //0表示月份  1表示年份
        if($status == 0)
        {
           $data['mon'] = $data['nums'];
        }else if($status == 1)
        {
            $data['year'] = $data['nums'];
        }
        $info = array();
        if($order->insertData($status,$data)) {
            $info['message'] = '购买成功';
        }else{
            $info['message'] = '购买失败';
        }
        $this->ajaxReturn($info);
        exit;
    }
}